package com.xuebank.nfe.nfecar.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by mac on 16/3/1.
 * 存放轻量级的数据
 */
public class CacheUtils {

    private static final String FILE_NAME = "cache";
    private static SharedPreferences        mPreference;
    private static SharedPreferences.Editor mEditor;

    public static void init(Context context) {

        mPreference = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
        mEditor = mPreference.edit();
    }

    public static boolean getBoolean(String key) {
        return mPreference.getBoolean(key, false);
    }

    public static void putBoolean(String key, boolean value) {
        mEditor.putBoolean(key, value).commit();
    }

    /**
     * 保存时自动加密
     **/
    public static void putString(String key, String value) {
        //      String text = EncryptionHelper.encodeString(value);
        mEditor.putString(key, value).commit();
    }

    /**
     * 读取时自动解密
     **/
    public static String getString(String key) {
        String value = mPreference.getString(key, "");
        //        String s = EncryptionHelper.decodeString(value);
        //        if(key == "Authorization") {
        //            return "Bearer"+" "+value;
        //        }
        return value;
    }


}
